<?php 
class APPFModelFeed extends APPObject 
{
	var $data	=	array();
	var $item	=	null;
	function APPFModelFeed()
	{
		
	}
	function getListFeed()
	{
		$db	=	Factory::getDBO();		
		$query	=	'SELECT siteID,domain '.
						' FROM `#__fconfig` '.
						' WHERE state = 1'.
						' ORDER BY id';
		$db->setQuery($query);
//		APPDatabase::loadResultArray();
		$arr	=	$db->loadObjectList();
		return $arr;
	}
	function getData()
	{
		if (count($this->data))
			return $this->data;
		$db	=	Factory::getDBO();
		$site	=	Request::getVar('site','vietbao');
		$query	=	'SELECT domain '.
						' FROM `#__fconfig` '.
						' WHERE state = 1 AND siteID = '. $db->quote("$site");
		$db->setQuery($query);
		$site	=	$db->loadResult();
		if (!$site)
			echo 'nodata';
		$query	=	'SELECT title,secName,catName,secid,catid,feedId,numberStore,numberView '.
						' FROM `#__feeds` '.
						' WHERE published = 1 AND link LIKE '. $db->quote("%$site%").
						' ORDER BY ordering';
		$db->setQuery($query);
//		APPDatabase::loadResultArray();
		$arr	=	$db->loadObjectList();
		$data	=	array();
		
		for ($i=0;$i<count($arr); $i++)
		{
			$obj	=	$arr[$i];
			if (isset($data[$obj->feedId]))
				continue;
			$obj_feed	=	new stdClass();
			$obj_feed->title	=	$obj->title;
			$obj_feed->feedId	=	$obj->feedId;
			$obj_feed->secName	=	$obj->secName;
			$obj_feed->catName	=	$obj->catName;
			$obj_feed->numberView	=	$obj->numberView;
			$obj_feed->data		=	$this->getFeed($obj->feedId,0,$obj->numberView);
			$data[$obj->feedId]	=	$obj_feed;
			
		}
		$this->data	=	$data;
		return $this->data;
	}
	
	function getFeed($fId, $start, $limit)
	{
		$db	=	Factory::getDBO();
		$query	=	'SELECT * FROM `#__fcontent` WHERE fid = '. $db->quote($fId).
							'	AND state = 1'.
							'	ORDER BY date_original 	DESC'.
							'	LIMIT '.$start.','. $limit;
		$db->setQuery($query);
		return $db->loadObjectList();
	}
	function getItem()
	{
		if ($this->item)
			return $this->item;
		$db	=	Factory::getDBO();
		$feedId	=	Request::getVar('feedId','');
		$start	=	Request::getVar('start',0);	
		$query	=	'SELECT title,secName,catName,secid,catid,feedId,numberStore,numberView '.
						' FROM `#__feeds` '.
						' WHERE published = 1 AND feedId = '. $db->quote($feedId);
		$db->setQuery($query);
//		APPDatabase::loadResultArray();
		if ($obj	=	$db->loadObject())
		{
			$obj_feed	=	new stdClass();
			$obj_feed->title	=	$obj->title;
			$obj_feed->feedId	=	$obj->feedId;
			$obj_feed->secName	=	$obj->secName;
			$obj_feed->catName	=	$obj->catName;
			$obj_feed->numberView	=	$obj->numberView;
			$obj_feed->data		=	$this->getFeed($obj->feedId,$start,$obj->numberView);		
			$this->item	=	$obj_feed;
			return $this->item;
		}
		return FALSE;
	}
}













?>